<%@ WebHandler Language="C#" Class="SiteMap" %>

//==========================================================================
// New HTTPHandler to generate SiteMap dynamically and return the generated XML
// Author: Deepak
// Date: 15 Jan 2008
//==========================================================================

using System;
using System.Web;
using System.Text;
using System.Xml;
using SiteManager;
using System.Data.SqlClient;

public class SiteMap : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {

        Manager objMan = new SiteManager.Manager();

        string strQuery = string.Empty;
        strQuery = "Select ID,Name FROM tbl_Speciality order by Name";
        SqlDataReader dr = objMan.ExecuteQuery(strQuery);
                
        //////Create XML        
        XmlTextWriter writer = new
             XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8);

        // start writing!
        writer.WriteStartDocument();
        writer.WriteStartElement("siteMap");

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/default.aspx");
        writer.WriteAttributeString("title", "Home");
        writer.WriteAttributeString("description", "Home Page");

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/SearchDoctors_adv.aspx");
        writer.WriteAttributeString("title", "Find a Doctor");
        writer.WriteAttributeString("description", "Find a Doctor");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/default.aspx#top");
        writer.WriteAttributeString("title", "Patient Login");
        writer.WriteAttributeString("description", "Patient Login");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/doctor/doctorlogin.aspx");
        writer.WriteAttributeString("title", "Doctor Login");
        writer.WriteAttributeString("description", "Doctor Login");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/advertise.aspx");
        writer.WriteAttributeString("title", "Advertise");
        writer.WriteAttributeString("description", "Advertise");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/FAQs.aspx");
        writer.WriteAttributeString("title", "Help");
        writer.WriteAttributeString("description", "Help");
        writer.WriteEndElement();

        // PATIENT
        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("title", "Patient");
        
        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/default.aspx#top2");
        writer.WriteAttributeString("title", "Login");
        writer.WriteAttributeString("description", "Login");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/SearchDoctors_adv.aspx#top2");
        writer.WriteAttributeString("title", "Search Doctors");
        writer.WriteAttributeString("description", "Search Doctors");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/patient/patient_rate.aspx");
        writer.WriteAttributeString("title", "Rate Doctors");
        writer.WriteAttributeString("description", "Rate Doctors");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/doctor/FeaturedDoctor.aspx");
        writer.WriteAttributeString("title", "Featured Doctors");
        writer.WriteAttributeString("description", "Featured Doctors");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/doctor/topDoctor.aspx");
        writer.WriteAttributeString("title", "Top Doctors");
        writer.WriteAttributeString("description", "Top Doctors");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/patient/patient_registration.aspx");
        writer.WriteAttributeString("title", "Registration");
        writer.WriteAttributeString("description", "Registration");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/patient/patient_password.aspx");
        writer.WriteAttributeString("title", "Forgot Password");
        writer.WriteAttributeString("description", "Forgot Password");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/tellafriend.aspx");
        writer.WriteAttributeString("title", "Tell a Friend");
        writer.WriteAttributeString("description", "Tell a Friend");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/FAQs.aspx#top");
        writer.WriteAttributeString("title", "FAQ");
        writer.WriteAttributeString("description", "FAQ");
        writer.WriteEndElement();
        
        writer.WriteEndElement();
        
        // DOCTORS

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("title", "Doctor");

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/doctor/doctorlogin.aspx#top");
        writer.WriteAttributeString("title", "Login");
        writer.WriteAttributeString("description", "Login");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/doctor/Doctorsubscription.aspx");
        writer.WriteAttributeString("title", "Become a Featured Doctor");
        writer.WriteAttributeString("description", "Become a Featured Doctor");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/doctor/doctorregistration.aspx");
        writer.WriteAttributeString("title", "Registration");
        writer.WriteAttributeString("description", "Registration");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/doctor/doctorForgotPass.aspx");
        writer.WriteAttributeString("title", "Forgot Password");
        writer.WriteAttributeString("description", "Forgot Password");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/doctor/doctorContent.aspx#1");
        writer.WriteAttributeString("title", "Doctor Center");
        writer.WriteAttributeString("description", "Doctor Center");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/doctor/doctorContent.aspx#2");
        writer.WriteAttributeString("title", "Connect with Doctors");
        writer.WriteAttributeString("description", "Connect with Doctors");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/doctor/doctorContent.aspx#3");
        writer.WriteAttributeString("title", "Doctor Endorsement");
        writer.WriteAttributeString("description", "Doctor Endorsement");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/doctor/FeaturedDoctor.aspx#1");
        writer.WriteAttributeString("title", "Featured Doctor");
        writer.WriteAttributeString("description", "Featured Doctor");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/FAQs.aspx#top1");
        writer.WriteAttributeString("title", "FAQ");
        writer.WriteAttributeString("description", "FAQ");
        writer.WriteEndElement();
        
        writer.WriteEndElement();
      //  writer.WriteElementString("ip", HttpContext.Current.Request.UserHostAddress);
        
        // DOCTOR DATABASE

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("title", "Doctor Database");

        while (dr.Read())
        {
            writer.WriteStartElement("siteMapNode");
            writer.WriteAttributeString("url", "~/doctors_specialty_" + dr["Name"].ToString().Trim().Replace(" ","_") + "/a.aspx");
            writer.WriteAttributeString("title", dr["Name"].ToString());
            writer.WriteAttributeString("description", dr["Name"].ToString());
            writer.WriteEndElement();
        }

        dr.Close();
        
        writer.WriteEndElement();

        // DENTIST

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("title", "Dentist");

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/dentist/dentistlogin.aspx#top");
        writer.WriteAttributeString("title", "Login");
        writer.WriteAttributeString("description", "Login");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/dentist/dentistsubscription.aspx");
        writer.WriteAttributeString("title", "Become a Featured Dentist");
        writer.WriteAttributeString("description", "Become a Featured Dentist");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/dentist/doctorregistration.aspx");
        writer.WriteAttributeString("title", "Registration");
        writer.WriteAttributeString("description", "Registration");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/dentist/dentistForgotPass.aspx");
        writer.WriteAttributeString("title", "Forgot Password");
        writer.WriteAttributeString("description", "Forgot Password");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/dentist/dentistContent.aspx#1");
        writer.WriteAttributeString("title", "Dentist Center");
        writer.WriteAttributeString("description", "Dentist Center");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/dentist/dentistContent.aspx#2");
        writer.WriteAttributeString("title", "Connect with Dentist");
        writer.WriteAttributeString("description", "Connect with Dentist");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/dentist/dentistContent.aspx#3");
        writer.WriteAttributeString("title", "Dentist Endorsement");
        writer.WriteAttributeString("description", "Dentist Endorsement");
        writer.WriteEndElement();

        writer.WriteEndElement();

        strQuery = "select id, specialty as name from tbl_DentistSpecialty where isdelete=0 order by Name";
        dr = objMan.ExecuteQuery(strQuery);

        // DENTIST DATABASE

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("title", "Dentist Database");

        while (dr.Read())
        {
            writer.WriteStartElement("siteMapNode");
            writer.WriteAttributeString("url", "~/dentist_specialty_" + dr["Name"].ToString().Trim().Replace(" ", "_") + "/a.aspx");
            writer.WriteAttributeString("title", dr["Name"].ToString());
            writer.WriteAttributeString("description", dr["Name"].ToString());
            writer.WriteEndElement();
        }

        dr.Close();

        writer.WriteEndElement();


        // BLOGS

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("title", "Boards &amp; Blogs");

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/boardsblogs/blogs.aspx");
        writer.WriteAttributeString("title", "Blogs");
        writer.WriteAttributeString("description", "Blogs");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/boardsblogs/blogs.aspx#1");
        writer.WriteAttributeString("title", "Doctor Message Boards");
        writer.WriteAttributeString("description", "Doctor Message Boards");
        writer.WriteEndElement();
        
        writer.WriteEndElement();


        // ABOUT

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("title", "About FindaDoc");

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/aboutus.aspx");
        writer.WriteAttributeString("title", "About Us");
        writer.WriteAttributeString("description", "About Us");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/terms.aspx");
        writer.WriteAttributeString("title", "Terms");
        writer.WriteAttributeString("description", "Terms");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/PrivacyPolicy.aspx");
        writer.WriteAttributeString("title", "Privacy");
        writer.WriteAttributeString("description", "Privacy");
        writer.WriteEndElement();

        writer.WriteStartElement("siteMapNode");
        writer.WriteAttributeString("url", "~/contactus.aspx");
        writer.WriteAttributeString("title", "Contact Us");
        writer.WriteAttributeString("description", "Contact Us");
        writer.WriteEndElement();
            
        writer.WriteEndElement();
                
        writer.WriteEndElement();
        writer.WriteEndDocument();
        writer.Close();


        context.Response.ContentType = "text/xml";
        context.Response.Write("");
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
}